package singleUseDeprecated;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonSyntaxException;
import com.google.gson.Strictness;

public class GsonBuilderSetLenientExample {

    public static String parseLenientJson(String json) {
        Gson gson = new GsonBuilder().setLenient().create();
        try {
            // 假设解析为简单的 Object 类
            Object result = gson.fromJson(json, Object.class);
            return gson.toJson(result);
        } catch (JsonSyntaxException e) {
            return "Invalid JSON: " + e.getMessage();
        }
    }

    //弃用API替换
    public static String parseLenientJson2(String json) {
        Gson gson = new GsonBuilder().setStrictness(Strictness.LENIENT).create();
        try {
            // 假设解析为简单的 Object 类
            Object result = gson.fromJson(json, Object.class);
            return gson.toJson(result);
        } catch (JsonSyntaxException e) {
            return "Invalid JSON: " + e.getMessage();
        }
    }

}
